// Have include guard.
#ifndef STATE_H
#define STATE_H

// Include files.
#include <map>
#include "WPILib.h"
#include "StateDoneCode.hpp"

/**
 *  The State class is used by the StateMachineController.
 *  
 *  The State class is the base class for states in the state machine in StateMachineController.
 *  States stores a transition map that maps a StateDoneCode to another State.
 *  When the state is done, it sets the "done code".  When the done code is set, the state machine
 *  moves on to the State specified by the transition map.
 *  
 *  This class seems to work.
 */
class State
{
	friend class StateMachineController;
	
	public:
		State();
		virtual ~State();
		const std::map<StateDoneCode, State*> &GetTransitions();
		void AddTransition(State &state);
		void AddTransition(StateDoneCode doneCode, State &state);
		void RemoveTransition(StateDoneCode doneCode);
		StateDoneCode GetDoneCode();
		State &GetNextState();
	protected:
		virtual void HandleActivate();
		virtual void HandlePeriodic();
		virtual void HandleContinuous();
		void SetDoneCode(StateDoneCode doneCode);
	private:
		std::map<StateDoneCode, State*> m_transitions;
		StateDoneCode m_doneCode;
		
		void Activate();
		void PeriodicInternal();
		void ContinuousInternal();
		
		DISALLOW_COPY_AND_ASSIGN(State);
};

#endif // #ifndef STATE_H 
